﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MvcSmartTool.Common {
    public abstract class BaseProjectWriter : IProjectWriter {
        public BaseProjectWriter(string solutionName) {
            SolutionName = solutionName;
        }
        public string SolutionName { get; set; }
        public abstract string ProjectName {
            get;
            
        }
        public string OutputPath { get; set; }
        public string ProjectPath {
            get {
                return Path.Combine(OutputPath, ProjectName);
            }
        }
        public void Generate() {
            FileWriterHelper.EnsurePath(Path.Combine(OutputPath, ProjectName));
            InternalGenerate();
        }
        protected abstract void InternalGenerate();
        public IList<TypeGenerationModel> Models {
            get;
            set;
        }
        protected void CopyTemplate(string fileName, string toDirectory, string nameSpace) {
            var text = File.ReadAllText(Path.Combine("./BaseTemplates", fileName + ".txt"));
            var newText = text.Replace("<#NAMESPACE#>", nameSpace);
            FileWriterHelper.WriteFile(toDirectory, fileName + ".cs", newText);
        }
        protected void CopyTemplate(string templateFileName, string outputFileName, string fromDic, string toDic, string solutionName){
            var text = File.ReadAllText(Path.Combine(fromDic, templateFileName));
            var newText = text.Replace("<#NAMESPACE#>", solutionName);

            FileWriterHelper.WriteFile(toDic, outputFileName, newText);
        }
    }
}
